Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

126
Visualizações
Upload multiple files with Ajax call [xhr] and send extra variable

I managed to send multiple documents to my controller using the following ajax call:

var fileData = new FormData();

            for (var i = 0; i < files.length; i++) {
                fileData.append("UploadDocumentsInput", files[i]);
            }

            $.ajax({
                type: "POST",
                url: "/LegalEntity/UploadFiles",
                async: false,
                dataType: "json",
                contentType: false, // Not to set any content header
                processData: true, // Not to process data
                data: fileData,
                success: function (result, status, xhr) {
                },
                error: function (xhr, status, error) {
                    documentSuccess = false;
                }
            });

and in the controller, I receive them this way:

 [HttpPost]
        public JsonResult UploadFiles()
        {
            var listOfDocs = new List<UploadedFile>();
            HttpFileCollectionBase files = Request.Files;

            for (int i = 0; i < files.Count; i++)
            {
                HttpPostedFileBase file = files[i];

                var inputStream = file.InputStream;
                var inputStreamLength = Convert.ToInt32(inputStream.Length);
                byte[] streamArray = new byte[inputStreamLength];
                var strRead = inputStream.Read(streamArray, 0, inputStreamLength);

                var docObject = new UploadedFile()
                {
                    Attachment = streamArray,
                    FileName = file.FileName,
                };

                listOfDocs.Add(docObject);
            }

            _personService.SaveDocs(listOfDocs);
            return Json(files.Count + " Files Uploaded!");
        }

But also, I will need to send from my view an ID. I have tried to include it into the data: field and receive it as argument into my method but this doesnt seem to be working.

Every help will be much appreciated.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda